package com.eig.order.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eig.common.entity.order.FormData;
import com.eig.common.entity.order.TOrder;
import com.eig.common.entity.order.TPayLog;
import com.eig.common.vo.order.OrderLog;
import com.eig.order.dao.TOrderDao;
import com.eig.order.dao.TPayLogDao;
import com.eig.order.service.TOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 订单(TOrder)表服务实现类
 *
 * @author makejava
 * @since 2022-12-07 18:43:30
 */
@Service("tOrderService")
public class TOrderServiceImpl implements TOrderService {
    @Resource
    private TOrderDao tOrderDao;

    @Resource
    private TPayLogDao tPayLogDao;


    @Override
    public Map getAllOrder(Integer currentPage, Integer pageSize, FormData formData) {
        Map map = new HashMap<String, Object>();
        QueryWrapper<TOrder> wrapper = new QueryWrapper<>();
        if (formData.getCourseName()!=""&&formData.getCourseName()!=null){
            wrapper.like("course_title",formData.getCourseName());
        }
        if(formData.getTeacherName()!=""&&formData.getTeacherName()!=null){
            wrapper.like("teacher_name",formData.getTeacherName());
        }
        if(formData.getOrderNo()!=""&&formData.getOrderNo()!=null){
            wrapper.eq("order_no",formData.getOrderNo());
        }
        if(formData.getPayType()!=null){
            wrapper.eq("pay_type",formData.getPayType());
        }
        if(formData.getStatus()!=null){
            wrapper.eq("status",formData.getStatus());
        }
        Long aLong = tOrderDao.selectCount(wrapper);
        wrapper.last("limit "+(currentPage-1)*pageSize+","+pageSize);
        List<TOrder> tOrders = tOrderDao.selectList(wrapper);
        map.put("allOrder",tOrders);
        map.put("total",aLong);
        return map;
    }

    @Override
    public OrderLog getByidOrderLog(String id) {
        TOrder tOrder = tOrderDao.selectById(id);
        QueryWrapper<TPayLog> wrapper = new QueryWrapper<>();
        wrapper.eq("order_no", tOrder.getOrderNo());
        TPayLog tPayLog = tPayLogDao.selectOne(wrapper);
        OrderLog orderLog = new OrderLog();
        orderLog.setTOrder(tOrder);
        orderLog.setTPayLog(tPayLog);
        return orderLog;
    }


}
